﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using IView.DiaryAndTracking;
using Engine;
using DataTransferObject.DiaryAndTrackingTask.SupportClassForUpdateTask;
using System.Data;
using DataTransferObject;

namespace Presenter.DiaryAndTracking
{
    public class PresenterTrackingTaskForm : Presenter
    {
        private JskeEngine jskeEngine = JskeEngine.getInstance(dataServiceMode);
        private ITrackingTaskForm _view;
        public PresenterTrackingTaskForm(ITrackingTaskForm view, int dataAccessMode)
        {
            Presenter.changeDataServiceMode(dataAccessMode);
            //tai tasklist va TaskTrackingData len
            jskeEngine.loadTrackingTaskData();
            jskeEngine.LoadTaskListFromFileToEngine();
            this._view = view;
        }

        public void saveTaskWorked(List<TaskWorked> listTW)
        {
            jskeEngine.saveListTaskWorked(listTW);
        }

        public List<TaskWorked> loadTaskWorked(DateTime from, DateTime to)
        {
            List<TaskWorked> result = jskeEngine.getTaskWorkFromTo(from.Date, to.Date);
            result.Sort(delegate(TaskWorked t1, TaskWorked t2){
                return t2.TimeStamp.CompareTo(t1.TimeStamp);
            });
            return result;
        }

        public DataTable loadTaskReport()
        {
            DataTable result = jskeEngine.loadTaskReport();
            result.Columns.RemoveAt(result.Columns.Count - 1);
            return result;

        }
        public DataTable loadSummaryReport()
        {
            return jskeEngine.loadSummaryReport();
        }

        public Task getTaskByID(int taskID)
        {
            return jskeEngine.getTaskByID(taskID);
        }

    }
}
